BASIC Scripts and Custom Functions

NOTE: This feature is only available in the Professional version of AutoMate

Subroutines

Although the AutoMate's library of available actions provides a robust set of functionality that may be configured visually. Occasionally, it may be necessary to utilize straight BASIC scripting to access API calls, COM objects or to perform other complex tasks. This is possible in AutoMate Professional, by using the built-in BASIC scripting engine. These BASIC scripts may be embedded directly into a task file, alternatively scripts may reference an external BAS file.

An example of this type of usage is shown below:

<!--- Create the variable --->
<AMVARIABLE NAME="NUMTOSQUARE">1</AMVARIABLE>
<AMVARIABLE NAME="theresult"></AMVARIABLE>
<!--- Ask the user to enter a number --->
<AMINPUTBOX WINDOWTITLE="Enter a number" RESULTVARIABLE="NUMTOSQUARE">Which number would you liked squared?</AMINPUTBOX>
<!--- Perform the calculation and add a string to result using a BASIC Script --->
<AMSCRIPT>Sub Main
  theresult = NUMTOSQUARE * NUMTOSQUARE
  theresult = &quot;The result is&quot; &amp; Str(theresult)
End Sub</AMSCRIPT>
<!--- Display result --->
<AMMESSAGEBOX>%theresult%</AMMESSAGEBOX>

Custom Functions

BASIC scripting can also be useful in the creation of Custom Functions, that is the creation of a function that performs a calculation and may be used as many times as needed in future steps as expressions. As a matter of fact, the above task would be more efficient if created in this manner.

An example of the same task restructured with a custom function is shown below:

<!--- Create the variable --->
<AMVARIABLE NAME="NUMTOSQUARE">1</AMVARIABLE>
<AMVARIABLE NAME="theresult"></AMVARIABLE>
<!--- Ask the user to enter a number --->
<AMINPUTBOX WINDOWTITLE="Enter a number" RESULTVARIABLE="NUMTOSQUARE">Which number would you liked squared?</AMINPUTBOX>
<!--- Perform the calculation and add a string to result using a BASIC Script --->
<AMSCRIPT>Function SquareNumber(thenumber)
  SquareNumber = thenumber * thenumber
End Function</AMSCRIPT>
<!--- Display result --->
<AMMESSAGEBOX>The result is %SquareNumber(numtosquare)%</AMMESSAGEBOX>
<AMMESSAGEBOX>The result is %SquareNumber(SquareNumber(numtosquare))%</AMMESSAGEBOX>

As you can see the basic script was converted into a custom function so that it can be called multiple times in the task and so that different values may be passed to it for processing. The function will of course yield a different result depending on the value passed to it.

See Also:

BASIC Script Action

Introduction to BASIC scripting

The BASIC Language Grouped by Type

Introduction to Extended Functions